package main

import "container/heap"

type IntHeap []int

func (h *IntHeap) Len() int {
	return len(*h)
}

func (h *IntHeap)  Less(i, j int) bool {
	arr := *h
	return arr[i] < arr[j]
}

func (h *IntHeap) Swap(i, j int) {
	(*h)[i], (*h)[j] =  (*h)[j], (*h)[i]
}

func (h *IntHeap) Push(x any) {
	(*h) = append((*h), x.(int))
}

func (h *IntHeap) Pop() any {
	x := (*h)[h.Len()-1]
	(*h) = (*h)[:h.Len()-1]
	return x
}

func numberGame(nums []int) []int {
	h := make(IntHeap, 0)
	heap.Init(&h)
	for _, x := range nums {
		heap.Push(&h, x)
	}
	var result []int
	for h.Len() > 0 {
		a := heap.Pop(&h).(int)
		b := heap.Pop(&h).(int)
		result = append(result, b, a)
	}
	return result
}

